package com.bocai.yuweiwangluo.activity;

import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.base.BaseActivity;
import com.bocai.yuweiwangluo.bean.BaseBean;
import com.bocai.yuweiwangluo.bean.MessageListBean;
import com.bocai.yuweiwangluo.net.MyOkHttpClient;
import com.bocai.yuweiwangluo.utils.TimeUtils;
import com.bocai.yuweiwangluo.utils.UrlData;
import com.google.gson.Gson;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

public class MessageDetailActivity extends BaseActivity {

    @ViewInject(R.id.tv_messagedetail_title)
    TextView tvTitle;
    @ViewInject(R.id.tv_messagedetail_time)
    TextView tvTime;
    @ViewInject(R.id.tv_messagedetail_content)
    TextView tvContent;
    private MessageListBean.DataEntity data;
    private String what;
    private static final int RESPONSE_SUCCEED = 1;
    private static final int RESPONSE_FAILED = 2;
    BaseBean baseBean=new BaseBean();
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            String result = (String) msg.obj;
            Gson gson = new Gson();
            switch (msg.what){
                case RESPONSE_SUCCEED:
                    baseBean=gson.fromJson(result,BaseBean.class);
                    break;
                case RESPONSE_FAILED:
                    break;
            }
        }
    };
    @Override
    protected int contentView() {
        return R.layout.activity_message_detail;
    }

    @Override
    protected void setData() {
        ViewUtils.inject(this);
        initToolbar("消息详情");
        data= (MessageListBean.DataEntity) getIntent().getSerializableExtra("data");
        what=getIntent().getStringExtra("what");
        if(data.getNickname()==null){
            tvTitle.setText(data.getTitle());
        }else{
            tvTitle.setText(data.getNickname());
        }
        tvTime.setText(TimeUtils.getTime_year_month_data(Long.parseLong(data.getTimeline())));
        if(data.getContent()!=null)
        {

            tvContent.setText(data.getContent().toString());
        }
        if(what.equals("no")){
            MyOkHttpClient myOkHttpClient=new MyOkHttpClient(this,this);
            myOkHttpClient.setMessage(UrlData.BASEURL + UrlData.SETMESSAGE, data.getId(), handler);
        }

    }
}
